package com.example.drzhang.oengldemo;

import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.drzhang.oengldemo.render.NewGLRender;
import com.example.drzhang.oengldemo.util.GLUtil;

public class MainActivity extends AppCompatActivity {

    private GLSurfaceView mGLSurfaceView;
//    private MyGLRender mMyGLRender;
    private NewGLRender mMyGLRender;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        setContentView(R.layout.activity_main);

        initGLSurfaceView();
    }

    private void initGLSurfaceView() {
        if (GLUtil.checkSupportOpenGl2(this)) {
            mGLSurfaceView = new GLSurfaceView(this);
            mGLSurfaceView.setEGLContextClientVersion(2);
            mMyGLRender = new NewGLRender(this);
            mGLSurfaceView.setRenderer(mMyGLRender);
            setContentView(mGLSurfaceView);
        }else{
            setContentView(R.layout.activity_main);
            Toast.makeText(this,"该设备不支持OpenGL ES2.0", Toast.LENGTH_SHORT).show();
        }
    }

    public void click(View view){
        initGlideView();
    }

    private void initGlideView(){
        String imgUrl = "http://img1.50tu.com/meinv/xinggan/2013-11-16/e65e7cd83f37eed87067299266152807.jpg";
        ImageView img = findViewById(R.id.img);
        Glide.with(this)
             .load(imgUrl)
             .into(img);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLSurfaceView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mGLSurfaceView.onPause();
    }

}
